package com.ruoyi.api.mail;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaMallProductLevel;
import com.ruoyi.system.domain.vo.JiajiaMallProductLevelVo;
import com.ruoyi.system.service.IJiajiaMallProductLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商城产品小类Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@Controller
@RequestMapping("/api/mall/level")
public class ApiJiajiaMallProductLevelController
{
    private String prefix = "mall/level";

    @Autowired
    private IJiajiaMallProductLevelService jiajiaMallProductLevelService;

    //@RequiresPermissions("system:level:view")
    @GetMapping()
    public String level()
    {
        return prefix + "/level";
    }

    /**
     * 查询商城产品小类列表
     */
    //@RequiresPermissions("system:level:list")
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(JiajiaMallProductLevel jiajiaMallProductLevel)
    {
        List<JiajiaMallProductLevelVo> list = jiajiaMallProductLevelService.selectJiajiaMallProductLevelList(jiajiaMallProductLevel);
        return AjaxResult.success(list);
    }

    /**
     * 导出商城产品小类列表
     */
    //@RequiresPermissions("system:level:export")
    @Log(title = "商城产品小类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaMallProductLevel jiajiaMallProductLevel)
    {
        List<JiajiaMallProductLevelVo> list = jiajiaMallProductLevelService.selectJiajiaMallProductLevelList(jiajiaMallProductLevel);
        ExcelUtil<JiajiaMallProductLevelVo> util = new ExcelUtil<JiajiaMallProductLevelVo>(JiajiaMallProductLevelVo.class);
        return util.exportExcel(list, "商城产品小类数据");
    }




    @GetMapping("/add/{typeId}")
    public String add(@PathVariable("typeId") String typeId, ModelMap mmap)
    {
        mmap.put("typeId", typeId);
        return prefix + "/add";
    }

    /**
     * 新增保存商城产品小类
     */
    //@RequiresPermissions("system:level:add")
    @Log(title = "商城产品小类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaMallProductLevel jiajiaMallProductLevel)
    {
        return AjaxResult.success(jiajiaMallProductLevelService.insertJiajiaMallProductLevel(jiajiaMallProductLevel));
    }

    /**
     * 修改商城产品小类
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaMallProductLevel jiajiaMallProductLevel = jiajiaMallProductLevelService.selectJiajiaMallProductLevelById(id);
        mmap.put("jiajiaMallProductLevel", jiajiaMallProductLevel);
        return prefix + "/edit";
    }

    /**
     * 修改保存商城产品小类
     */
    //@RequiresPermissions("system:level:edit")
    @Log(title = "商城产品小类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaMallProductLevel jiajiaMallProductLevel)
    {
        return AjaxResult.success(jiajiaMallProductLevelService.updateJiajiaMallProductLevel(jiajiaMallProductLevel));
    }

    /**
     * 删除商城产品小类
     */
    //@RequiresPermissions("system:level:remove")
    @Log(title = "商城产品小类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return AjaxResult.success(jiajiaMallProductLevelService.deleteJiajiaMallProductLevelByIds(ids));
    }


    @GetMapping("/select")
    @ResponseBody
    public List<JiajiaMallProductLevelVo> select(Long typeId){
        JiajiaMallProductLevel jiajiaMallProductLevel=new JiajiaMallProductLevel();
        jiajiaMallProductLevel.setTypeId(typeId);
        List<JiajiaMallProductLevelVo> list1 = jiajiaMallProductLevelService.selectJiajiaMallProductLevelList(jiajiaMallProductLevel);
        return  list1;
    }


}
